package org.assertj.ohos.api.bluetooth;

import ohos.bluetooth.BluetoothDeviceClass;
import org.assertj.core.api.AbstractAssert;

import static org.assertj.ohos.internal.BitmaskUtils.buildNamedValueString;
import static org.assertj.core.api.Assertions.assertThat;

public class BluetoothClassAssert extends AbstractAssert<BluetoothClassAssert, BluetoothDeviceClass> {
  public BluetoothClassAssert(BluetoothDeviceClass actual) {
    super(actual, BluetoothClassAssert.class);
  }

  public BluetoothClassAssert hasDeviceClass(int deviceClass) {
    isNotNull();
    int actualClass = actual.getMajorClass();
    assertThat(actualClass) //
        .overridingErrorMessage("Expected device class <%s> but was <%s>.",
            deviceClassToString(deviceClass), deviceClassToString(actualClass)) //
        .isEqualTo(actualClass);
    return this;
  }

  public BluetoothClassAssert hasMajorDeviceClass(int majorDeviceClass) {
    isNotNull();
    int actualMajorDeviceClass = actual.getMajorMinorClass();
    assertThat(majorDeviceClass) //
        .overridingErrorMessage("Expected major device class <%s> but was <%s>.",
            majorDeviceClassToString(majorDeviceClass),
            majorDeviceClassToString(actualMajorDeviceClass)) //
        .isEqualTo(majorDeviceClass);
    return this;
  }

  public BluetoothClassAssert hasService(int service) {
    isNotNull();
    assertThat(actual.isServiceSupported(service)) //
        .overridingErrorMessage("Expected to have service <%s> but did not.",
            serviceToString(service)) //
        .isTrue();
    return this;
  }

  public BluetoothClassAssert doesNotHave(int service) {
    isNotNull();
    assertThat(actual.isServiceSupported(service)) //
        .overridingErrorMessage("Expected to not have service <%s> but did.",
            serviceToString(service)) //
        .isFalse();
    return this;
  }

  public static String deviceClassToString(int deviceClass) {
    return buildNamedValueString(deviceClass) //
        .value(BluetoothDeviceClass.MajorMinorClass.AUDIO_VIDEO_CAMCORDER, "AUDIO_VIDEO_CAMCORDER")
        .value(BluetoothDeviceClass.MajorMinorClass.AUDIO_VIDEO_CAR_AUDIO, "AUDIO_VIDEO_CAR_AUDIO")
        .value(BluetoothDeviceClass.MajorMinorClass.AUDIO_VIDEO_HANDSFREE_DEVICE, "AUDIO_VIDEO_HANDSFREE_DEVICE")
        .value(BluetoothDeviceClass.MajorMinorClass.AUDIO_VIDEO_HEADPHONES, "AUDIO_VIDEO_HEADPHONES")
        .value(BluetoothDeviceClass.MajorMinorClass.AUDIO_VIDEO_HIFI_AUDIO_DEVICE, "AUDIO_VIDEO_HIFI_AUDIO_DEVICE")
        .value(BluetoothDeviceClass.MajorMinorClass.AUDIO_VIDEO_LOUDSPEAKER, "AUDIO_VIDEO_LOUDSPEAKER")
        .value(BluetoothDeviceClass.MajorMinorClass.AUDIO_VIDEO_MICROPHONE, "AUDIO_VIDEO_MICROPHONE")
        .value(BluetoothDeviceClass.MajorMinorClass.AUDIO_VIDEO_PORTABLE_AUDIO, "AUDIO_VIDEO_PORTABLE_AUDIO")
        .value(BluetoothDeviceClass.MajorMinorClass.AUDIO_VIDEO_SET_TOP_BOX, "AUDIO_VIDEO_SET_TOP_BOX")
        .value(BluetoothDeviceClass.MajorMinorClass.AUDIO_VIDEO_UNCATEGORIZED, "AUDIO_VIDEO_UNCATEGORIZED")
        .value(BluetoothDeviceClass.MajorMinorClass.AUDIO_VIDEO_VCR, "AUDIO_VIDEO_VCR")
        .value(BluetoothDeviceClass.MajorMinorClass.AUDIO_VIDEO_VIDEO_CAMERA, "AUDIO_VIDEO_VIDEO_CAMERA")
        .value(BluetoothDeviceClass.MajorMinorClass.AUDIO_VIDEO_VIDEO_CONFERENCING,
            "AUDIO_VIDEO_VIDEO_CONFERENCING")
        .value(BluetoothDeviceClass.MajorMinorClass.AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER,
            "AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER")
        .value(BluetoothDeviceClass.MajorMinorClass.AUDIO_VIDEO_VIDEO_GAMING_TOY, "AUDIO_VIDEO_VIDEO_GAMING_TOY")
        .value(BluetoothDeviceClass.MajorMinorClass.AUDIO_VIDEO_VIDEO_MONITOR, "AUDIO_VIDEO_VIDEO_MONITOR")
        .value(BluetoothDeviceClass.MajorMinorClass.AUDIO_VIDEO_WEARABLE_HEADSET, "AUDIO_VIDEO_WEARABLE_HEADSET")
        .value(BluetoothDeviceClass.MajorMinorClass.COMPUTER_DESKTOP_WORKSTATION, "COMPUTER_DESKTOP_WORKSTATION")
        .value(BluetoothDeviceClass.MajorMinorClass.COMPUTER_HANDHELD_PC_PDA, "COMPUTER_HANDHELD_PC_PDA")
        .value(BluetoothDeviceClass.MajorMinorClass.COMPUTER_LAPTOP, "COMPUTER_LAPTOP")
        .value(BluetoothDeviceClass.MajorMinorClass.COMPUTER_PALM_SIZE_PC_PDA, "COMPUTER_PALM_SIZE_PC_PDA")
        .value(BluetoothDeviceClass.MajorMinorClass.COMPUTER_SERVER_CLASS, "COMPUTER_SERVER_CLASS")
        .value(BluetoothDeviceClass.MajorMinorClass.COMPUTER_UNCATEGORIZED, "COMPUTER_UNCATEGORIZED")
        .value(BluetoothDeviceClass.MajorMinorClass.COMPUTER_WEARABLE, "COMPUTER_WEARABLE")
        .value(BluetoothDeviceClass.MajorMinorClass.HEALTH_BLOOD_PRESSURE_MONITOR, "HEALTH_BLOOD_PRESSURE_MONITOR")
        .value(BluetoothDeviceClass.MajorMinorClass.HEALTH_HEALTH_DATA_DISPLAY, "HEALTH_HEALTH_DATA_DISPLAY")
        .value(BluetoothDeviceClass.MajorMinorClass.HEALTH_GLUCOSE_METER, "HEALTH_GLUCOSE_METER")
        .value(BluetoothDeviceClass.MajorMinorClass.HEALTH_PULSE_OXIMETER, "HEALTH_PULSE_OXIMETER")
        .value(BluetoothDeviceClass.MajorMinorClass.HEALTH_HEART_PULSE_RATE_MONITOR, "HEALTH_HEART_PULSE_RATE_MONITOR")
        .value(BluetoothDeviceClass.MajorMinorClass.HEALTH_THERMOMETER, "HEALTH_THERMOMETER")
        .value(BluetoothDeviceClass.MajorMinorClass.HEALTH_UNDEFINED, "HEALTH_UNDEFINED")
        .value(BluetoothDeviceClass.MajorMinorClass.HEALTH_WEIGHING_SCALE, "HEALTH_WEIGHING_SCALE")
        .value(BluetoothDeviceClass.MajorMinorClass.PHONE_CELLULAR, "PHONE_CELLULAR")
        .value(BluetoothDeviceClass.MajorMinorClass.PHONE_CORDLESS, "PHONE_CORDLESS")
        .value(BluetoothDeviceClass.MajorMinorClass.PHONE_COMMON_ISDN_ACCESS, "PHONE_COMMON_ISDN_ACCESS")
        .value(BluetoothDeviceClass.MajorMinorClass.PHONE_MODEM_OR_VOICE_GATEWAY, "PHONE_MODEM_OR_VOICE_GATEWAY")
        .value(BluetoothDeviceClass.MajorMinorClass.PHONE_SMARTPHONE, "PHONE_SMARTPHONE")
        .value(BluetoothDeviceClass.MajorMinorClass.PHONE_UNCATEGORIZED, "PHONE_UNCATEGORIZED")
        .value(BluetoothDeviceClass.MajorMinorClass.TOY_CONTROLLER, "TOY_CONTROLLER")
        .value(BluetoothDeviceClass.MajorMinorClass.TOY_DOLL_ACTION_FIGURE, "TOY_DOLL_ACTION_FIGURE")
        .value(BluetoothDeviceClass.MajorMinorClass.TOY_GAME, "TOY_GAME")
        .value(BluetoothDeviceClass.MajorMinorClass.TOY_ROBOT, "TOY_ROBOT")
//        .value(BluetoothDeviceClass.MajorMinorClass.TOY_UNCATEGORIZED, "TOY_UNCATEGORIZED")
        .value(BluetoothDeviceClass.MajorMinorClass.TOY_VEHICLE, "TOY_VEHICLE")
        .value(BluetoothDeviceClass.MajorMinorClass.WEARABLE_GLASSES, "WEARABLE_GLASSES")
        .value(BluetoothDeviceClass.MajorMinorClass.WEARABLE_HELMET, "WEARABLE_HELMET")
        .value(BluetoothDeviceClass.MajorMinorClass.WEARABLE_JACKET, "WEARABLE_JACKET")
        .value(BluetoothDeviceClass.MajorMinorClass.WEARABLE_PAGER, "WEARABLE_PAGER")
//        .value(BluetoothDeviceClass.MajorMinorClass.WEARABLE_UNCATEGORIZED, "WEARABLE_UNCATEGORIZED")
        .value(BluetoothDeviceClass.MajorMinorClass.WEARABLE_WRIST_WATCH, "WEARABLE_WRIST_WATCH")
        .get();
  }

  public static String majorDeviceClassToString(int majorDeviceClass) {
    return buildNamedValueString(majorDeviceClass) //
        .value(BluetoothDeviceClass.MajorClass.AUDIO_VIDEO, "audio_video")
        .value(BluetoothDeviceClass.MajorClass.COMPUTER, "computer")
        .value(BluetoothDeviceClass.MajorClass.HEALTH, "health")
        .value(BluetoothDeviceClass.MajorClass.IMAGING, "imaging")
        .value(BluetoothDeviceClass.MajorClass.MISCELLANEOUS, "MISCELLANEOUS")
        .value(BluetoothDeviceClass.MajorClass.NETWORK_ACCESS, "NETWORK_ACCESS")
        .value(BluetoothDeviceClass.MajorClass.PERIPHERAL, "peripheral")
        .value(BluetoothDeviceClass.MajorClass.PHONE, "phone")
        .value(BluetoothDeviceClass.MajorClass.TOY, "toy")
        .value(BluetoothDeviceClass.MajorClass.UNCATEGORIZED, "uncategorized")
        .value(BluetoothDeviceClass.MajorClass.WEARABLE, "wearable")
        .get();
  }

  public static String serviceToString(int service) {
    return buildNamedValueString(service) //
        .value(BluetoothDeviceClass.Service.AUDIO, "audio")
        .value(BluetoothDeviceClass.Service.CAPTURING, "CAPTURING")
        .value(BluetoothDeviceClass.Service.INFORMATION, "information")
        .value(BluetoothDeviceClass.Service.LIMITED_DISCOVERABLE_MODE, "LIMITED_DISCOVERABLE_MODE")
        .value(BluetoothDeviceClass.Service.NETWORKING, "networking")
        .value(BluetoothDeviceClass.Service.OBJECT_TRANSFER, "object_transfer")
        .value(BluetoothDeviceClass.Service.POSITIONING, "positioning")
        .value(BluetoothDeviceClass.Service.RENDERING, "RENDERING")
        .value(BluetoothDeviceClass.Service.TELEPHONY, "telephony")
        .get();
  }
}
